package com.verssor.api;


import com.verssor.model.Chofer;
import com.verssor.service.commons.ChoferService;

import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.util.ArrayList;
import java.util.List;

@Path("/chofer")
@RequestScoped
public class ChoferAPI {

    @Inject
    ChoferService choferService;
    
    @POST
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.APPLICATION_JSON)
    @Path("/create")
    public Response create(Chofer chofer){
        return Response.ok().build();
    }

    @Path("/list")
    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public List<Chofer> list(){
        
        Chofer ch1 = new Chofer();
        Chofer ch2 = new Chofer();
        Chofer ch3 = new Chofer();
        
        ch1.setApellido("Burgos");
        ch2.setApellido("Farino");
        ch3.setApellido("Navarro");
        List<Chofer> choferes = new ArrayList<Chofer>();
        
        choferes.add(ch1);
        choferes.add(ch2);
        choferes.add(ch3);
        
        return choferes;
    }

    @GET
    @Produces(MediaType.APPLICATION_JSON)
    @Path("/find")
    public Chofer find( @QueryParam("id")  Integer id){
        
        Chofer ch1 = new Chofer();
        ch1.setApellido("Burgos");
        return ch1;        
    }

    @GET
    @Produces(MediaType.APPLICATION_JSON)
    @Path("/init")
    public List<Chofer> init(){

        Chofer ch1 = new Chofer();
        Chofer ch2 = new Chofer();
        Chofer ch3 = new Chofer();

        ch1.setApellido("Burgos");
        ch2.setApellido("Farino");
        ch3.setApellido("Navarro");
        List<Chofer> choferes = new ArrayList<Chofer>();

        choferService.create(ch1);
        choferService.create(ch2);
        choferService.create(ch3);

        choferes.add(ch1);
        choferes.add(ch2);
        choferes.add(ch3);
        
        return choferes;
    }
    
}
